<?php
	//Start the session
	session_start();
	
	//Get required classes
	require_once 'LoginView.php';
	require_once 'LoginHandler.php';
	require_once 'LoginController.php';
	require_once 'PageView.php';
	
	//Variables to store title and body
	$title = "Loginpage";
	$header = "<h2>Great login service</h2>";
	$body = "";
	
	//var_dump($_GET);
	
	//Create instances of our MVC object
	$loginViewer = new LoginView();
	$loginHandler = new LoginHandler();
	//$controller = new controller();
	
	//Generate some XHTML...
	$loginDiv = $loginViewer->generateLoginBox();
	$logoutButton = $loginViewer->generateLogoutButton();	
	
	//Test our stuff
	if ($loginViewer->triedToLogin() ){
		if($loginHandler->isUserLoggedIn()){
			$body .= "<p>Allready logged in as: " . $_SESSION[LoginHandler::UserName] ."</p>";
		}
		else{
			if($loginHandler->logIn($loginViewer->getUserName(), $loginViewer->getPassword())){
				$body .= "<p>Hey " . $loginViewer->getUserName() .", Your in pall!!!</p>";
			}
			else{
				$body .= "<p>Incorrect credentials man</p>";
			}
		}
		//$body .= "Användaren har klickat på Login med användarnamn <br />";
		//$body .= $loginViewer->getUserName() . " och lösenord " . $loginViewer->getPassword() ;
	}
	else {
		$body .= "<p>User has not clicked Login</p>";
	}
	
	if ($loginViewer->triedToLogOut() ){
		if($loginHandler->logOut()){
			$body .= "<p>User clicked Logout<p/>";
		}
		else{
			$body .="<p>You must login to logout!</p>";
		}
	}
	else{
		$body .= "<p>User did not click Logout</p>";
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sv">

<head>
	<title><?php echo $title; ?></title>
	<meta http-equiv="content-type" 
		content="text/html;charset=utf-8" />
</head>

<body>
	<?php
		echo $header;
		echo $loginDiv;
		echo $logoutButton;
		echo $body;		
	?>
</body>
</html>